package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.GradeLayer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 班级分层设置 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-08-26
 */
public interface GradeLayerMapper extends BaseMapper<GradeLayer> {


    @Select({"<script>",
            "SELECT",
                    "count( id ) AS count ",
                    "FROM",
                    "grade_layer ",
                    "WHERE",
                    "year_part = ${yearPart} ",
                    "AND quarter_num = ${quarterNum} ",
                    "AND subjects_id = ${subjectsId} ",
                    "AND class_type_id = ${classTypeId} ",
                    "AND FIND_IN_SET( ${yearClassId}, year_class_id_str ) ",
                    "AND ( ${startScore} BETWEEN start_score AND end_score ) ",
                    "AND ( ${endScore} BETWEEN start_score AND end_score ) ",
                    "AND lesson_type = ${lessonType}",
            "</script>"})
    public Integer getLayerCount(@Param("yearPart") Integer yearPart,
                                 @Param("quarterNum") Integer quarterNum,
                                 @Param("subjectsId") Long subjectsId,
                                 @Param("yearClassId") Integer yearClassId,
                                 @Param("classTypeId") Long classTypeId,
                                 @Param("lessonType") Integer lessonType,
                                 @Param("startScore") BigDecimal startScore,
                                 @Param("endScore") BigDecimal endScore
                                 );

    @Select({"<script>",
            "SELECT",
            "*",
            "FROM",
            "grade_layer ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND subjects_id = ${subjectsId} ",
            "AND class_type_id = ${classTypeId} ",
            "AND FIND_IN_SET( ${yearClassId}, year_class_id_str ) ",
            "AND lesson_type = ${lessonType}",
            "</script>"})
    public List<GradeLayer> getLayerList(@Param("yearPart") Integer yearPart,
                             @Param("quarterNum") Integer quarterNum,
                             @Param("subjectsId") Long subjectsId,
                             @Param("yearClassId") Integer yearClassId,
                             @Param("classTypeId") Long classTypeId,
                             @Param("lessonType") Integer lessonType
    );

    @Select({"<script>",
            "SELECT",
            "*",
            "FROM",
            "grade_layer ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND subjects_id = ${subjectsId} ",
            "AND class_type_id = ${classTypeId} ",
            "AND FIND_IN_SET( ${yearClassId}, year_class_id_str ) ",
            "AND lesson_type = ${lessonType}",
            "LIMIT 1",
            "</script>"})
    public GradeLayer getLayer(@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("subjectsId") Long subjectsId, @Param("yearClassId") Integer yearClassId, @Param("classTypeId") Long classTypeId, @Param("lessonType") Integer lessonType);

}
